package jrain.fw.id.snowflake;

import jrain.fw.core.id.IdService;
import jrain.fw.core.service.Service;
import jrain.fw.core.service.ServiceConst;
import jrain.fw.core.utils.FwUtils;
import jrain.utils.lang.LangUtils;

/**
 * <pre>
 * 作者：489088214@qq.com 
 * 描述：ID生成服务
 * </pre>
 */
@Service(name = "snowflake", group = ServiceConst.S_ID_SERVICE, module = ServiceConst.M_ID)
public class IdSnowflakeService implements IdService {

	private final IdWorker idWorker;

	public IdSnowflakeService() {
		Object workerIdStr = FwUtils.getCfgService().getCfgValue(ServiceConst.M_ID, "server.id", "0");
		int workerId = LangUtils.parseInt(workerIdStr);
		idWorker = new IdWorker(workerId);
	}

	public long nextId() {
		return idWorker.nextId();
	}

	@Override
	public String uuid() {
		return LangUtils.randomUUID();
	}

}
